﻿namespace NGroup.VTL.Web.Controllers
{
    using System.Collections.Generic;
    using System.Web.Mvc;
    using NGroup.VTL.Core.Const;
    using NGroup.VTL.Models;
    using NGroup.VTL.Service;
    using NGroup.VTL.WebCore;
    using NGroup.VTL.Service.Abstraction;

    public class tin_tucController : ContentBaseController
    {
        #region Constructor

        private IRetrieveContentService _retrieveContentService;

        public tin_tucController()
        {
            _retrieveContentService = new RetrieveContentService();
        }

        public tin_tucController(IRetrieveContentService retrieveContentService)
        {
            _retrieveContentService = retrieveContentService;
        }

        #endregion

        public ActionResult danh_sach()
        {
            PagingInfoModel pagingInfo = this.GetPagingParameters();

            List<NewsModel> newsModelList = _retrieveContentService.GetNewsListByTypeAndPagingInfo(4, CurrentLanguage, ref pagingInfo);

            ViewBag.PagingInfo = pagingInfo;
            ViewBag.MetaKeyword = NGroup.VTL.Resources.Lang.tintuc_defaultmetakeywords;
            ViewBag.MetaDescription = NGroup.VTL.Resources.Lang.tintuc_defaultmetadescriptions;

            return View(newsModelList);
        }

        public ActionResult chi_tiet(string id)
        {
            var model = _retrieveContentService.GetNewsDetail(id, CurrentLanguage);
            ViewBag.UniqueString = model.Title;
            ViewBag.MetaKeyword = model.MetaContent;
            ViewBag.MetaDescription = model.MetaDescription;
            return View(model);
        }

        private PagingInfoModel GetPagingParameters()
        {
            var pagingInfo = new PagingInfoModel();

            string currentPage = Request.Form["currentPage"];
            string pageSize = Request.Form["pageSize"];

            int currentPageValue, pageSizeValue;

            pagingInfo.CurrentPage = int.TryParse(currentPage, out currentPageValue) ? currentPageValue : 1;
            pagingInfo.PageSize = int.TryParse(pageSize, out pageSizeValue) ? pageSizeValue : GeneralConfiguration.PageSize;

            return pagingInfo;
        }
    }
}
